<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.lp.cfg.ProConfig"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/WEB-INF/oss/iot/common/variable.jsp"%>
<%@ include file="/WEB-INF/oss/iot/common/variable_js.jsp"%>
<%@ include file="/WEB-INF/oss/iot/common/resource_lib.jsp"%>

<style type="text/css">
	#map {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
	.mapContainer{
		height: 550px;width:100%;
	}
	.dashboard-menu{
		border-top:1px solid #ecf0f5;
	}
	.app-container{
		background:  #f2f2f2;width: 100%;border-top:1px solid #ecf0f5;
	}
	
	.box-white {
	    width: 97%;
	    min-width: 897px;
	    padding-bottom: 0;
	    margin: 0 auto;
	}
	.box {
	    padding: 10px;
	    padding-top:1px;
	    border-left: 1px solid #d2d6de;
	    border-right: 1px solid #d2d6de;
	    border-bottom: 1px solid #d2d6de;
	}
	.box {
	    border: 0!important;
	    box-shadow: 0 0 2px 1px rgba(13,5,9,.08)!important;
	}
	.box {
	    position: relative;
	    border-radius: 3px;
	    background: #fff;
	    border-top: 3px solid #d2d6de;
	    margin-bottom: 20px;
		width:800px;
		margin: 0 auto;
	    box-shadow: 0 1px 1px rgba(0,0,0,.1);
	}
	.sceneList-info{
		padding-top: 10px;
		padding-left: 10px;
	}
	.p-title{
		padding: 20px 0;
		font-size: 20px;
		margin-left: -50px;
	}
	.generateStyle{
		position: absolute;
		top: 18px;
		right: 15px;
		cursor: pointer;
	}
</style>
</head>
<body>
	<div>
		<!--  下方部位  -->
		<div style="background: #ecf0f5;">
			<div class="mapContainer" >
				<div class="app-container">
					<div class="container-layout sceneList-info">
						<div class="box join-device-box">
							<div class="clearfix" style="width: 600px;margin: 0 auto;">
								<div>
									<p class="p-title">添加传感点信息</p>
								</div>
								<div id="modify-sensor"  config-option=" 'url':'/sensor','method':'put',
													  'submit':'.save-Btn',
													  'success':'sunccessReturn' ">
								<div id="add-sensor"  config-option=" 'url':'/sensor',
												  'submit':'.save-Btn',
												  'success':'sunccessReturn' ">
									<div id="detail_get" config-option="  url:'/sensor?id=$#init-id$' , success:'initSuccess' ">
										<input type="hidden" type-name="id" id="init-id" >
										<input type="hidden" class="scene_id">
										<div class="clearfix">
											<div class="form-line float-left" style="width: 49%;">
												<span class="red">*</span>&nbsp;<span>传感点名称：</span>
												<div class="pb-10 pt-10">
													<input placeholder="输入传感点名称" validate="empty" type-name="name" class="input input-big" >
												</div>	
											</div>
											<div class="form-line float-left" style="width: 49%;margin-left: 2%;">
												<span class="red">*</span>&nbsp;<span>所属设备：</span>
												<div class="pb-10 pt-10">
													<select type-name="node_id" validate="empty:请选择设备号" config-option=" url:'/page/node?paged=1&pageSize=100',key:'id',value:'name',init_value:'请选择所属设备', data :{scene_id:'$.scene_id$'} " class="input input-big input-select jui-selecter" ></select>
												</div>
											</div>
										</div>
										<div class="clearfix">
											<div class="form-line float-left" style="width: 49%;">
												<span class="red">*</span>&nbsp;<span>数据类型：</span>
												<div class="pb-10 pt-10">
													<select class="input input-big input-select jui-selecter" onchange="sensordataTypeChange(this)" type-name="data_type"   >
														<option value="0">数据属性</option>
														<option value="1">配置属性</option>
														<option value="2">报警属性</option>
													</select>
												</div>
											</div>
											<div class="form-line float-left" style="width: 49%;margin-left: 2%;">
												<span class="red">*</span>&nbsp;<span>数据精度：</span>
												<div class="pb-10 pt-10">
													<select class="input input-big input-select jui-selecter" type-name="sdata_degree"  >
														<option value="2">请选择小数点位数</option>
														<option value="0">0</option>
														<option value="1">1</option>
														<option value="2">2</option>
														<option value="3">3</option>
														<option value="4">4</option>
														<option value="5">5</option>
														<option value="6">6</option>
													</select>
												</div>
											</div>
										</div>
										<div class="clearfix">
											<div class="form-line float-left" style="width: 49%;" >
												<span class="red">*</span>&nbsp;<span>地址号：</span>
												<div class="pb-10 pt-10">
													<input placeholder="输入地址号，从机地址" validate="empty,num:输入数字类型号" type-name="sensor_device_id" class="input input-big" >
												</div>	
											</div>
											<div class="form-line float-left" style="width: 49%;margin-left: 2%;" >
												<span class="red">*</span>&nbsp;<span>寄存器号：</span>
												<div class="pb-10 pt-10">
													<input type-name="port_id" placeholder="偏移量" validate="empty,num:输入数字" class="input input-big" >
												</div>
											</div>
										</div>
										
										<div class="form-line">
											<div class=" dataType float-left" style="width: 49%;">
												<span class="red">*</span>&nbsp;<span>传感点类型：</span>
												<div class="pb-10 pt-10">
													<select type-name="iot_sensor_type" validate="empty" onchange="chageInfo(this);"  type-option="selecter" config-option="'method':'GET','url':'/dictionary/24','key':'code','value':'name','init_value':'请选择传感点类型','type':'list' "  class="input input-big input-select stype" ></select>
												</div>
											</div>
											
											<div class=" dataType float-left" style="width: 49%;margin-left: 2%;">
												<span>单位：</span>
												<div class="pb-10 pt-10">
													<select type-name="measure_unit_type" type-option="selecter" config-option="'method':'GET','url':'/dictionary/20','key':'code','value':'name','init_value':'请选择传感点单位','type':'list' "  class="input input-big input-select" ></select>
												</div>
											</div>
										</div>
										
										<div class="form-line aav">
											<div class="form-line hide aav" >
												<span class="red">*</span>&nbsp;<span>默认值：</span>
												<div class="pb-10 pt-10">
													<input type-name="param_type" placeholder="默认值" validate="empty" class="input input-big" >
												</div>
											</div>
										</div>
										
										<div class="form-line " >
											<div class="form-line hide paramType float-left" style="width: 49%;">
												<span class="red">*</span>&nbsp;<span>属性默认值：</span>
												<div class="pb-10 pt-10">
													<input type-name="sdata" placeholder="默认值" validate="empty" class="input input-big" >
												</div>
											</div>
											<div class="form-line hide paramType float-left" style="width: 49%;margin-left: 2%;" >
												<span>属性单位：</span>
												<div class="pb-10 pt-10">
													<input type-name="param_config" placeholder="属性的单位，如 °C 或者启动状态"  class="input input-big" >
												</div>
											</div>
										</div>
										
										<div class="form-line hide paramType">
											<span class="red">*</span>&nbsp;<span>参数备注：</span>
											<div class="pb-10 pt-10">
												<input type-name="param_names" placeholder="请输入备注信息" validate="empty" class="input input-big" >
											</div>
										</div>
										
										<div class="clearfix">
											<div class="form-line  float-left" style="width: 49%;">
												<span>公式处理(正向)：</span>
												<div class="pb-10 pt-10">
													<input type-name="formula_up" placeholder="公式计算，如 x/100 可不填" class="input input-big clear-v" >
												</div>
											</div>
											<div class="form-line  float-left" style="width: 49%;margin-left: 2%;">
												<span>公式处理(反向)：</span>
												<div class="pb-10 pt-10">
													<input type-name="formula_down" placeholder="公式计算，如 x*100 可不填" class="input input-big clear-v" >
												</div>
											</div>
										</div>
										
										<div class="form-line">
											<span>参数配置：</span>
											<div class="pb-10 pt-10"  style="position: relative;">
												<input placeholder="请输入参数配置"  type-name="infos" readonly="readonly" class="input input-big infos" >
												<img class="generateStyle self-icon" tag='参数配置' onclick="generateCode(this)" src="<%=basePath%>/image/oss/iot/settings.png">
											</div>	
										</div>
										
										<div class="form-line">
											<span>排序：</span>
											<div class="pb-10 pt-10">
												<input placeholder="显示顺序" type="number" value="1"  validate="empty"  type-name="seq" class="input input-big" >
											</div>	
										</div>
										<div class="form-line clearfix" style="padding-bottom: 20px;">
											<button onclick="returnBack()"  class="cancel-btn button ml-20  border-gray button-big float-right">取消</button>
											<button class="save-Btn button bg-iot ml-10 button-big float-right">保存</button>
										</div>
									</div>
								</div>
								</div>
							</div>
							
						</div>
						<div style="height: 40px;"></div>
					</div>
				</div>
			</div>
		</div>
		
		<div id="editSetting" style="display:none;padding:20px;">
			<div style="min-height: 150px;">
			<div class="form-line">
				<span class="red">*</span>&nbsp;<span>属性种类：</span>
				<div class="pb-10 pt-10">
					<select class="input input-big input-select catetoryInfo" onchange="selChange(this);" >
						<option value='0' >请选择对应配置</option>
						<option value='1' >Modbus RTU</option>
						<option value='2' >默认</option>
					</select>
				</div>	
			</div>
			<div class="form-line hide modbusrtu">
				<span>功能码：</span>
				<div class="pb-10 pt-10">
					<select class="input input-big input-select fcode" >
						<option value='01' >01</option>
						<option value='02' >02</option>
						<option value='03' >03</option>
						<option value='04' >04</option>
						<option value='05' >05</option>
						<option value='06' >06</option>
					</select>
				</div>
			</div>
			<div class="form-line hide modbusrtu">
				<span>数据格式：</span>
				<div class="pb-10 pt-10">
					<select class="input input-big input-select datayute" onchange="typeChange(this)" >
						<option value='uint' >16位 无符号数</option>
						<option value='int' >16位 有符号数</option>
						<option value='uint32' >32位 无符号数</option>
						<option value='float' >32位 浮点型数</option>
					</select>
				</div>
			</div>
			
			<div class="form-line hide orderbyinfoc">
				<span>数据顺序：</span>
				<div class="pb-10 pt-10">
					<select class="input input-big input-select orderbyinfo" >
						<option value='ABCD' >AB CD</option>
						<option value='CDAB' >CD AB</option>
					</select>
				</div>
			</div>
			
			<div class="form-line clearfix">
				<button onclick="closeAll();" class="button border-gray ml-10 button-big float-right">取消</button>
				<button onclick="saveInfo();" class="button ml-20 bg-iot button-big float-right">保存</button>
			</div>
			</div>
		</div>
		
	</div>
</body>
<script type="text/javascript">
function sunccessReturn(){
	forwardUrl("/iot/sensor_manager?id="+GetQueryString("id"),1000,"保存成功");	
}
function returnBack(){
	forwardUrl('/iot/sensor_manager?id='+GetQueryString("id"));
}

function generateCode(obj){
	$(".modbusrtu").hide();
	$(".catetoryInfo").val(2);
	if( !validater.empty( $(".infos").val() ) ){
		var data = $.parseJSON( $(".infos").val() );
		if( data["fcode"] != null ){
			$(".fcode").val(data["fcode"]);
			$(".datayute").val(data["type"]);
			$(".modbusrtu").show();
			if(data["type"] == 'float'  ){
				$(".orderbyinfoc").show();
				$(".orderbyinfo").val(data["order"]);
			}
			$(".catetoryInfo").val(1);
		}
	}
	openWindow("参数配置","#editSetting","500px");
}

function selChange(obj){
	if($(obj).val() == 1){
		$(".modbusrtu").show();
	}else{
		$(".modbusrtu").hide();
		$(".orderbyinfoc").hide();
	}
}

function saveInfo(){
	if( $(".catetoryInfo").val() ==1 ){
		// modbus rtu 配置
		var data = {} ;
		data["fcode"] = $(".fcode").val();
		data["type"]=$(".datayute").val();
		if( !$(".orderbyinfoc").is(":hidden") ){
			data["order"]=$(".orderbyinfo").val();
		}
		$(".infos").val(JSON.stringify(data));
	}else{
		$(".infos").val("");
	}
	tip("设置成功");
	setTimeout(function() {
		closeAll();
	}, 1000);
	
}

$(function(){
	// 初始化url参数
	var id = GetQueryString("id");
	$(".scene_id").val(id);
	
	var sid = GetQueryString("sid");
	if(validater.empty(sid)){
		manual_form_submit($("#add-sensor"))
	}else{
		$(".p-title").html("编辑传感点信息");
		writeVal("init-id",sid);
		manual_form_submit($("#modify-sensor"));
		setTimeout(function(){
			manual_init_detail_get($("#detail_get"));			
		}, 150);
	}

	table_operate_init();
})

function sensordataTypeChange(obj){
	if( $(obj).val() == 0 || $(obj).val() == 2 ){
		$(".dataType").show();
		$(".paramType").hide();
	}else{
		$(".dataType").hide();
		$(".paramType").show();
	}
}

function initSuccess(){
	if(gsc('data_type').val() == 0 || gsc('data_type').val() == 2 ){
		$(".dataType").show();
		$(".paramType").hide();
	}else{
		$(".dataType").hide();
		$(".paramType").show();
	}
	
	if( $(".stype").val() == 190 ){
		$(".aav").show();
	}else{
		$(".aav").hide();
	}
	
}

function typeChange(obj){
	if( $(obj).val() == 'float' ){
		$(".orderbyinfoc").show();
	}else{
		$(".orderbyinfoc").hide();
	}
}

function chageInfo(obj){
	if( $(obj).val() == 190 ){
		$(".aav").show();
	}else{
		$(".aav").hide();
	}
}
</script>
</html>